var AUTH = require('../../utils/auth')
const API = require('../../pages/api/index')
import {
  get,
  post
} from '../../request/index'

Page({

  /**
   * 页面数据源
   */
  data: {
    loading: true,
    show: false,
    parentld: 0,
    arr: [],
    prolist: {},
    titleName: "",
    meetingList: [],
    taskList: [],
    taskTypeList: [],
    showBOBlist: [],
    task: "您还未有待办任务",
    tasks: "您还未有待办任务"
  },

  onLoad() {
    this.gridGet()
  },
  onShow() {
    if (this.data.prolist.userId) {
      this.meeting()
    }
  },
  handTimeChang(e) {
    if (!Object.hasOwn(e.detail, 'children')) {
      wx.navigateTo({
        url: `${e.detail.component}`,
      })

    } else {
      wx.navigateTo({
        url: `/pages/nextGrid/nextGrid`,
        success: (res) => {
          // 发送一个事件
          res.eventChannel.emit('eventChannelNextGrid', { data: e.detail.children, title: e.detail.meta.title })
        }
      })
    }


  },
  async gridGet() {
    get('/system/user/getInfo').then(res => {
      if (res.code == 200) {
        this.setData({
          prolist: res.user
        })
        this.meeting()
        wx.setStorageSync('prolist', JSON.stringify(res.user));
        get('/system/menu/getAppRouters', {
          userId: res.user.userId
        }).then(res => {
          this.setData({
            arr: res.data[0].children,
            loading: false,
          })
        })
      } else {
        wx.showToast({
          title: res.msg,
          duration: 3000,
          mask: true
        })
      }

    })
  },
  async meeting() {
    let res = await get('/app/notify/list', {
      userId: this.data.prolist.userId
    })
    console.log(res);
    if (res.code == 200) {
      this.setData({
        taskTypeList: res.rows,
        tasks: ""
      })
    }
  },
  tapName() {
    wx.navigateTo({
      url: '/pages/meeting/meeting'
    })
  },
  more() {
    wx.navigateTo({
      url: '/pages/meetingmore/meetingmore'
    })
  },
  taskmore() {
    wx.navigateTo({
      url: '/pages/taskmore/taskmore'
    })
  },
  onClose(e) {
    this.setData({
      show: false
    })
  },
  task(e) {
    this.setData({
      show: true,
      showBOBlist: e.currentTarget.dataset.item.taskListVoList
    })
    console.log(e.currentTarget.dataset.item);
    switch (e.currentTarget.dataset.item.type) {
      case 1:
        wx.navigateTo({
          url: '/pages/lmplementation/lmplementation?active=1'
        })
        break;
      case 2:
        wx.navigateTo({
          url: '/pages/dangerConfirm/dangerConfirm'
        })
        break;
      case 3:
        wx.navigateTo({
          url: '/pages/dangerRectification/dangerRectification'
        })
        break;
      case 4:
        wx.navigateTo({
          url: '/pages/dangerAlarm/dangerAlarm'
        })
        break;
      case 5:
        wx.navigateTo({
          url: '/pages/dangerRecord/dangerRecord?active=1'
        })
        break;
        case 7:
        wx.navigateTo({
          url: '/pages/dangerRecord/dangerRecord'
        })
        break;
      default:
        break;
    }
  },

  taskpop(e) {
    console.log(e);
    this.setData({
      show: false
    })
  },

  onPullDownRefresh: function () {
    wx.showLoading({
      title: '刷新中...',
    })
    this.gridGet()
    this.meeting()
    wx.hideLoading();
    wx.stopPullDownRefresh()

  },


})